<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .father {
      width: 400px;
      height: 400px;
      background-color: pink;
    }

    .son {
      width: 100px;
      height: 100px;
      background-color: blue;
      margin-top: 100px;
    }

    /* 这里的.clearfix::before解决了margin的塌陷现象 */
    .clearfix::before,
    .clearfix::after {
      content: '';
      display: table;
    }

    .clearfix::after {
      clear: both;
    }
  </style>
</head>

<body>
  <div class="father clearfix">
    <div class="son"></div>
  </div>
</body>

</html>